package com.achen.direct;

import com.achen.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * @author achen
 * @create 2020-05-10 22:54
 */
public class Provider {
    public static void main(String[] args) throws IOException {
        //获取连接
        Connection connection = RabbitMQUtil.getConnection();
        //获取通道对象
        Channel channel = connection.createChannel();
        //交换机名称
        String exchangeName = "logs_direct";
        //通过通道声明交换机以及交换机的类型
        //参数1：交换机名称
        //参数2：direct ---> 路由模式
        channel.exchangeDeclare(exchangeName, "direct");
        //路由key
        String routingKey = "error";
        //发送消息
        channel.basicPublish(exchangeName, routingKey, null, ("这是direct模型发布的基于routingKey：[" + routingKey + "]发送的消息").getBytes());
        //关闭资源
        RabbitMQUtil.closeConnectionAndChannel(channel, connection);
    }
}
